n = int(input())
m = []
for _ in range(n):
    line = list(map(int, input().split()))
    m.append(line)
# m = [[0]*(n+2)]
# for _ in range(n):
#     line = list(map(int, input().split()))
#     m.append([0]+line+[0])
# m.append([0]*(m+2))
dp = [[0 for _ in range(n)] for _ in range(n)]
count = 0
for i in range(0, n):
    for j in range(0, n):
        if m[i][j] == 1:
            if dp[i][j] == 0:
                dp[i][j] = count+1
                if i-1>0 and m[i-1][j] == 1: dp[i-1][j] = (count+1)
                if j-1>0 and m[i][j-1] == 1: dp[i][j-1] = (count+1)
                if i+1<n and m[i+1][j] == 1: dp[i+1][j] = (count+1)
                if j+1<n and m[i][j+1] == 1: dp[i][j+1] = (count+1)
                count += 1
            else:
                if i - 1 > 0 and m[i - 1][j] == 1: dp[i - 1][j] = dp[i][j]
                if j - 1 > 0 and m[i][j - 1] == 1: dp[i][j - 1] = dp[i][j]
                if i + 1 < n and m[i + 1][j] == 1: dp[i + 1][j] = dp[i][j]
                if j + 1 < n and m[i][j + 1] == 1: dp[i][j - 1] = dp[i][j]

print(count)




